home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / tex.ps < prev   
Encoding:
Text File  |  1988-11-15  |  11.7 KB  |  334 lines

  1. %!              for use by dvi2ps Version 2.00
  2. % a start (Ha!) at a TeX mode for PostScript.
  3. % The following defines procedures assumed and used by program "dvi2ps"
  4. % and must be downloaded or sent as a header file for all TeX jobs.
  5.  
  6. % By:  Neal Holtz, Carleton University, Ottawa, Canada
  7. %      <holtz@cascade.carleton.cdn>
  8. %      <holtz%cascade.carleton.cdn@ubc.csnet>
  9. %      June, 1985
  10. %      Last Modified: Aug 25/85
  11. % oystr 12-Feb-1986
  12. %   Changed @dc macro to check for a badly formed bits in character
  13. %   definitions.  Can get a <> bit map if a character is not actually
  14. %   in the font file.  This is absolutely guaranteed to drive the
  15. %   printer nuts - it will appear that you can no longer define a
  16. %   new font, although the built-ins will still be there.
  17.  
  18. % To convert this file into a downloaded file instead of a header
  19. % file, uncomment all of the lines beginning with %-%
  20.  
  21. %-%0000000             % Server loop exit password
  22. %-%serverdict begin exitserver
  23. %-%  systemdict /statusdict known
  24. %-%  {statusdict begin 9 0 3 setsccinteractive /waittimeout 300 def end}
  25. %-% if
  26.  
  27. /TeXDict 200 dict def   % define a working dictionary
  28. TeXDict begin           % start using it.
  29.  
  30.                         % units are in "dots" (300/inch)
  31. /Resolution 300 def
  32. /Inch  {Resolution mul} def  % converts inches to internal units
  33.  
  34. /Mtrx 6 array def
  35.  
  36. %%%%%%%%%%%%%%%%%%%%% Page setup (user) options %%%%%%%%%%%%%%%%%%%%%%%%
  37.  
  38. % dvi2ps will output coordinates in the TeX system ([0,0] 1" down and in
  39. % from top left, with y +ive downward).  The default PostScript system
  40. % is [0,0] at bottom left, y +ive up.  The Many Matrix Machinations in
  41. % the following code are an attempt to reconcile that. The intent is to
  42. % specify the scaling as 1 and have only translations in the matrix to
  43. % properly position the text.  Caution: the default device matrices are
  44. % *not* the same in all PostScript devices; that should not matter in most 
  45. % of the code below (except for lanscape mode -- in that, rotations of
  46. % -90 degrees resulted in the the rotation matrix [ e 1 ]
  47. %                                                 [ 1 e ]
  48. % where the "e"s were almost exactly but not quite unlike zeros.
  49.  
  50. /@letter
  51.   { letter initmatrix
  52.     72 Resolution div dup neg scale          % set scaling to 1.
  53.     310 -3005 translate      % move origin to top (these are not exactly 1"
  54.     Mtrx currentmatrix pop   % and -10" because margins aren't set exactly right)
  55.   } def
  56.         % note mode is like letter, except it uses less VM
  57. /@note
  58.   { note initmatrix
  59.     72 Resolution div dup neg scale          % set scaling to 1.
  60.     310 -3005 translate                      % move origin to top
  61.     Mtrx currentmatrix pop
  62.   } def
  63.  
  64. /@landscape
  65.   { letter initmatrix
  66.     72 Resolution div dup neg scale          % set scaling to 1.
  67. %    -90 rotate                              % it would be nice to be able to do this
  68.     Mtrx currentmatrix 0 0.0 put             % but instead we have to do things like this because what
  69.     Mtrx 1 -1.0 put                          % should be zero terms aren't (and text comes out wobbly)
  70.     Mtrx 2 1.0 put                           % Fie!  This likely will not work on QMS printers
  71.     Mtrx 3 0.0 put                           % (nor on others where the device matrix is not like
  72.     Mtrx  setmatrix                          %  like it is on the LaserWriter).
  73.     300 310  translate                       % move origin to top
  74.     Mtrx currentmatrix pop
  75.   } def
  76.  
  77. /@legal
  78.   { legal initmatrix
  79.     72 Resolution div dup neg scale          % set scaling to 1.
  80.     295 -3880 translate                      % move origin to top
  81.     Mtrx currentmatrix pop
  82.   } def
  83.  
  84. /@manualfeed
  85.    { statusdict /manualfeed true put
  86.    } def
  87.         % n @copies -   set number of copies
  88. /@copies
  89.    { /#copies exch def
  90.    } def
  91.  
  92. %%%%%%%%%%%%%%%%%%%% Procedure Defintions %%%%%%%%%%%%%%%%%%%%%%%%%%
  93.  
  94. /@newfont       % id @newfont -         -- initialize a new font dictionary
  95.   { /newname exch def
  96.     pop
  97.     newname 7 dict def          % allocate new font dictionary
  98.     newname load begin
  99.         /FontType 3 def
  100.         /FontMatrix [1 0 0 -1 0 0] def
  101.         /FontBBox [0 0 1 1] def
  102.         /BitMaps 128 array def
  103.         /BuildChar {CharBuilder} def
  104.         /Encoding 128 array def
  105.         0 1 127 {Encoding exch /.undef put} for
  106.         end
  107.     newname newname load definefont pop
  108.   } def
  109.  
  110.  
  111. % the following is the only character builder we need.  it looks up the
  112. % char data in the BitMaps array, and paints the character if possible.
  113. % char data  -- a bitmap descriptor -- is an array of length 6, of 
  114. %          which the various slots are:
  115.  
  116. /ch-image {ch-data 0 get} def   % the hex string image
  117. /ch-width {ch-data 1 get} def   % the number of pixels across
  118. /ch-height {ch-data 2 get} def  % the number of pixels tall
  119. /ch-xoff  {ch-data 3 get} def   % number of pixels below origin
  120. /ch-yoff  {ch-data 4 get} def   % number of pixels to left of origin
  121. /ch-tfmw  {ch-data 5 get} def   % spacing to next character
  122.  
  123. /CharBuilder    % fontdict ch Charbuilder -     -- image one character
  124.   { /ch-code exch def           % save the char code
  125.     /font-dict exch def         % and the font dict.
  126.     /ch-data font-dict /BitMaps get ch-code get def     % get the bitmap descriptor for char
  127.     ch-data null eq not
  128.       { ch-tfmw   0   ch-xoff neg   ch-yoff neg   ch-width ch-xoff sub   ch-height ch-yoff sub
  129.             setcachedevice
  130.         ch-width ch-height true [1 0  0 1  ch-xoff ch-yoff]
  131.             {ch-image} imagemask
  132.       }
  133.     if
  134.   } def
  135.  
  136.  
  137. /@sf            % fontdict @sf -        -- make that the current font
  138.   { setfont() pop
  139.   } def
  140.  
  141.                 % in the following, the font-cacheing mechanism requires that
  142.                 % a name unique in the particular font be generated
  143.  
  144. /@dc            % char-data ch @dc -    -- define a new character bitmap in current font
  145.   { /ch-code exch def
  146. % ++oystr 12-Feb-86++
  147.     dup 0 get
  148.     length 2 lt
  149.       { pop [ <00> 1 1 0 0 8.00 ] } % replace <> with null
  150.     if
  151. % --oystr 12-Feb-86--
  152.     /ch-data exch def
  153.     currentfont /BitMaps get ch-code ch-data put
  154.     currentfont /Encoding get ch-code 
  155.        dup (   ) cvs cvn   % generate a unique name simply from the character code
  156.        put
  157.   } def
  158.  
  159. /@bop0           % n @bop0 -              -- begin the char def section of a new page
  160.   { 
  161.   } def
  162.  
  163. /@bop1           % n @bop1 -              -- begin a brand new page
  164.   { pop
  165.     erasepage initgraphics 
  166.     Mtrx setmatrix
  167.     /SaveImage save def() pop
  168.   } def
  169.  
  170. /@eop           % - @eop -              -- end a page
  171.   { showpage 
  172.     SaveImage restore() pop
  173.   } def
  174.  
  175. /@start         % - @start -            -- start everything
  176.   { @letter                             % (there is not much to do)
  177.   } def
  178.  
  179. /@end           % - @end -              -- done the whole shebang
  180.   { end
  181.   } def
  182.  
  183. /p              % x y p -               -- move to position
  184.   { moveto
  185.   } def
  186.  
  187. /r              % x r -                 -- move right
  188.   { 0 rmoveto
  189.   } def
  190.  
  191. /s              % string s -            -- show the string
  192.   { show
  193.   } def
  194.  
  195. /c              % ch c -                -- show the character (code given)
  196.   { c-string exch 0 exch put
  197.     c-string show
  198.   } def
  199.  
  200. /c-string ( ) def
  201.  
  202. /ru             % dx dy ru -   -- set a rule (rectangle)
  203.   { /dy exch neg def    % because dy is height up from bottom
  204.     /dx exch def
  205.     /x currentpoint /y exch def def   % remember current point
  206.     newpath x y moveto
  207.     dx 0 rlineto
  208.     0 dy rlineto
  209.     dx neg 0 rlineto
  210.     closepath fill
  211.     x y moveto
  212.   } def
  213.  
  214. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  215. %%     the \special command junk
  216. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  217. %   The structure of the PostScript produced by dvi2ps for \special is:
  218. %         @beginspecial
  219. %           - any number of @hsize, @hoffset, @hscale, etc., commands
  220. %         @setspecial
  221. %           - the users file of PostScript commands
  222. %         @endspecial
  223.  
  224. % The @beginspecial command recognizes whether the Macintosh Laserprep
  225. % has been loaded or not, and redfines some Mac commands if so.
  226. % The @setspecial handles the users shifting, scaling, clipping commands
  227.  
  228.  
  229. % The following are user settable options from the \special command.
  230.  
  231. /@SpecialDefaults
  232.   { /hs 8.5 Inch def
  233.     /vs 11 Inch def
  234.     /ho 0 def
  235.     /vo 0 def
  236.     /hsc 1 def
  237.     /vsc 1 def
  238.     /CLIP false def
  239.   } def
  240.  
  241. %       d @hsize -      specify a horizontal clipping dimension
  242. %                       these 2 are executed before the MacDraw initializations
  243. /@hsize {/hs exch def /CLIP true def} def
  244. /@vsize {/vs exch def /CLIP true def} def
  245. %       d @hoffset -    specify a shift for the drwgs
  246. /@hoffset {/ho exch def} def
  247. /@voffset {/vo excl def} def
  248. %       s @hscale -     set scale factor
  249. /@hscale {/hsc exch def} def
  250. /@vscale {/vsc exch def} def
  251.  
  252. /@setclipper
  253.   { hsc vsc scale
  254.     CLIP
  255.       { newpath 0 0 moveto hs 0 rlineto 0 vs rlineto hs neg 0 rlineto closepath clip }
  256.     if
  257.   } def
  258.  
  259. % this will be invoked as the result of a \special command (for the
  260. % inclusion of PostScript graphics).  The basic idea is to change all
  261. % scaling and graphics back to defaults, but to shift the origin
  262. % to the current position on the page.  Due to TeXnical difficulties,
  263. % we only set the y-origin.  The x-origin is set at the left edge of
  264. % the page.
  265.  
  266. /@beginspecial          % - @beginspecial -     -- enter special mode
  267.   { gsave /SpecialSave save def
  268.           % the following magic incantation establishes the current point as
  269.           % the users origin, and reverts back to default scalings, rotations
  270.     currentpoint transform initgraphics itransform translate
  271.     @SpecialDefaults    % setup default offsets, scales, sizes
  272.     @MacSetUp           % fix up Mac stuff 
  273.   } def
  274.  
  275. /@setspecial    % to setup user specified offsets, scales, sizes (for clipping)
  276.   {
  277.     MacDrwgs
  278.       {md begin /pxt ho def /pyt vo neg def end}
  279.       {ho vo translate @setclipper}
  280.     ifelse
  281.   } def
  282.  
  283. /@endspecial            % - @endspecial -       -- leave special mode
  284.   { SpecialSave restore
  285.     grestore
  286.   } def
  287.  
  288. /MacDrwgs false def     % will get set if we think the Mac LaserPrep file has been loaded
  289.  
  290.         % - @MacSetUp -   turn-off/fix-up all the MacDraw stuff that might hurt us
  291.                         % we depend on 'psu' being the first procedure executed
  292.                         % by a Mac document.  We redefine 'psu' to adjust page
  293.                         % translations, and to do all other the fixups required.
  294.                         % This stuff will not harm other included PS files
  295. /@MacSetUp
  296.   { userdict /md known  % if md is defined
  297.       { userdict /md get type /dicttype eq      % and if it is a dictionary
  298.          { /MacDrwgs true def
  299.            md begin                             % then redefine some stuff
  300.               /psu                              % redfine psu to set origins, etc.
  301.                 /psu load
  302.                         % this procedure contains almost all the fixup code
  303.                 { /letter {} def        % it is bad manners to execute the real
  304.                   /note {} def          %   versions of these (clears page image, etc.)
  305.                   /legal {} def
  306.                   statusdict /waittimeout 300 put
  307.                   /page {pop} def       % no printing of pages
  308.                   /pyt vo neg def       % x & y pixel translations
  309.                   /pxt ho def
  310.                 }
  311.                 concatprocs 
  312.               def
  313.               /od                               % redefine od to set clipping region
  314.                 /od load
  315.                 { @setclipper }
  316.                 concatprocs
  317.               def
  318.            end }
  319.         if }
  320.     if    
  321.   } def
  322.  
  323. %       p1 p2 concatprocs p       - concatenate procedures
  324. /concatprocs
  325.   { /p2 exch cvlit def 
  326.     /p1 exch cvlit def
  327.     /p p1 length p2 length add array def
  328.     p 0 p1 putinterval 
  329.     p p1 length p2 putinterval
  330.     p cvx
  331.   } def
  332.  
  333. end                     % revert to previous dictionary
  334.